<?php

include_once '../DBPersist.php';

class Vara {
    
    //campos da objeto
    //var $_cdVara;

    var $_query;

    function gravaVara($cdVara, $cdOrgao, $dsVara, $cdServentia, $dsEmail) {
        $_banco = new DBPersist();

        $_banco->sql_db("INSERT INTO Vara (cdVara, cdOrgao, dsVara, cdServentia, dsEmail)
             VALUES ($cdVara, $cdOrgao, '$dsVara',  $cdServentia, '$dsEmail')");
    }

    function deletaVara($cdVara, $cdOrgao) {
        $_banco = new DBPersist();
        $_banco->sql_db("DELETE FROM Vara WHERE cdVara='$cdVara' and cdOrgao='$cdOrgao'");
    }

    function alteraVara($cdVara, $cdOrgao, $dsVara, $cdServentia, $dsEmail) {
        $_banco = new DBPersist();
        $_banco->sql_db("UPDATE Vara SET dsVara='$dsVara',
                         cdServentia='$cdServentia', dsEmail='$dsEmail'
                         WHERE cdVara=$cdVara and cdOrgao=$cdOrgao");
    }

    function listaVara($cdVara, $cdOrgao) {
        $_banco = new DBPersist();
        $_banco->sql_db("SELECT cdVara, cdOrgao, cdServentia, dsEmail, dsVara FROM vara
				WHERE cdVara=$cdVara and cdOrgao=$cdOrgao");
        $temp = mysql_fetch_array($_banco->result);
        $this->_cdVara = $temp['cdVara'];
        $this->_cdOrgao = $temp['cdOrgao'];
        $this->_cdServentia = $temp['cdServentia'];
        $this->_dsEmail = $temp['dsEmail'];
        $this->_dsVara = $temp['dsVara'];
    }

    function listaTudoVara() {
        $_banco = new DBPersist();
        $_banco->sql_db("SELECT cdVara, cdOrgao, dsVara, cdServentia, dsEmail FROM vara ORDER BY cdVara DESC");
        return $_banco->result;
    }

}
?>